package itbour.onetouchshow.activity.version1_2;

import com.alibaba.fastjson.JSON;
import com.lsjr.callback.EncryBeanCallBack;
import com.lsjr.utils.HttpUtils;

import java.util.HashMap;
import java.util.List;

import itbour.onetouchshow.App;
import itbour.onetouchshow.base.mvp.BasePresenterImpl;
import itbour.onetouchshow.bean.CoverFrameTime;
import itbour.onetouchshow.constants.AppConfig;
import itbour.onetouchshow.constants.AppConst;
import itbour.onetouchshow.utils.L_;
import itbour.onetouchshow.utils.T_;

/**
 * MVPPlugin
 * 邮箱 784787081@qq.com
 */

public class CutVideoPresenter extends BasePresenterImpl<CutVideoContract.View> implements CutVideoContract.Presenter {

    public CutVideoPresenter(CutVideoContract.View view) {
        this.mvpView = view;
    }


    public void cliptAndSave() {

    }

    public void removevideoUserdoccover_v1_3(String docId) {
        HashMap<String, Object> stringObjectHashMap = new HashMap<>();
        stringObjectHashMap.put("device", AppConst.ANDROID_DEVICE);
        stringObjectHashMap.put("userId", App.getUserId());
        stringObjectHashMap.put("docId", docId);
        HttpUtils.getInstance().executeGet(AppConfig.REMOVEVIDEOUSERDOCCOVER_V1_3, stringObjectHashMap, new EncryBeanCallBack() {
            @Override
            protected void onXError(String exception) {
                T_.showCustomToast(exception);
            }

            @Override
            protected void onSuccess(String response) {

                if (mvpView != null) {
                    mvpView.setVideouserdoccoverSuccess();
                }
            }
        });
    }


    public void setVideouserdoccover_v1_3(String docId, double coverTime) {
        HashMap<String, Object> stringObjectHashMap = new HashMap<>();
        stringObjectHashMap.put("device", AppConst.ANDROID_DEVICE);
        stringObjectHashMap.put("userId", App.getUserId());
        stringObjectHashMap.put("docId", docId);
        stringObjectHashMap.put("coverTime", coverTime);
        HttpUtils.getInstance().executeGet(AppConfig.SETVIDEOUSERDOCCOVER_V1_3, stringObjectHashMap, new EncryBeanCallBack() {
            @Override
            protected void onXError(String exception) {
                T_.showCustomToast(exception);
            }

            @Override
            protected void onSuccess(String response) {

                if (mvpView != null) {
                    mvpView.setVideouserdoccoverSuccess();
                }

            }
        });
    }


    /*
* 作品预览
* */
    public void loadDocPreview(String docId) {
        L_.e("作品预览" + docId);
        HashMap<String, Object> stringObjectHashMap = new HashMap<>();
        stringObjectHashMap.put("device", AppConst.ANDROID_DEVICE);
        stringObjectHashMap.put("userId", App.getUserId());
        stringObjectHashMap.put("docId", docId);
        HttpUtils.getInstance().executeGet(AppConfig.GETDOCPREVIEW_V1_0, stringObjectHashMap, new EncryBeanCallBack() {
            @Override
            protected void onXError(String exception) {
                T_.showCustomToast(exception);
                if (mvpView != null) {
                    mvpView.loadFaild(exception);
                }
            }

            @Override
            protected void onSuccess(String response) {
                if (mvpView != null) {
                    L_.e(response);
                    mvpView.loadDocPreviewSuccess();
                }
            }
        });
    }


    /*
* 获取作品关键帧
* */
    public void getuserDockeyframetimes_v1_3(String docId) {
        L_.e("作品预览" + docId);
        HashMap<String, Object> stringObjectHashMap = new HashMap<>();
        stringObjectHashMap.put("device", AppConst.ANDROID_DEVICE);
        stringObjectHashMap.put("userId", App.getUserId());
        stringObjectHashMap.put("docId", docId);
        HttpUtils.getInstance().executeGet(AppConfig.GETUSERDOCKEYFRAMETIMES_V1_3, stringObjectHashMap, new EncryBeanCallBack() {
            @Override
            protected void onXError(String exception) {
                // T_.showCustomToast(exception);
                if (mvpView != null) {
                    mvpView.loadFaild(exception);
                }
            }

            @Override
            protected void onSuccess(String response) {
                if (mvpView != null) {
                    L_.e(response);
                    CoverFrameTime coverFrameTime = JSON.parseObject(response, CoverFrameTime.class);
                    List<Double> keyFrameTimes = coverFrameTime.getKeyFrameTimes();
                    Double[] array = new Double[keyFrameTimes.size()];
                    for (int i = 0; i < keyFrameTimes.size(); i++) {
                        array[i] = keyFrameTimes.get(i);
                    }
                    mvpView.getKeyFrameTimes(array);
                    //List<Double> listString = JSON.parseArray(response, Double.class);
                    //  Double[] doubles = (Double[]) listString.toArray();
                    //L_.e(doubles[0]+"");
                    // JSON.parseArray("keyFrameTimes",)
                }
            }
        });
    }

}
